/** @Controller */
// @Bind view.onReady
!function(self, arg) {
	String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
		if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
		    return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
		} else {
		    return this.replace(reallyDo, replaceWith);
		}
	};
};

//@Bind #blockViewLeft.onCreate
!function(self, arg) {
	self.set("renderer", new dorado.widget.blockview.ImageBlockRenderer({
		imageProperty : "bigIcon",
		tipProperty :"name"
	}));
};

//@Bind ^mainMenuBlock.onCreate
!function(self, arg) {
	self.set("renderer", new dorado.widget.blockview.ImageBlockRenderer({
		captionProperty : "name",
		imageProperty : "bigIcon"
	}));
};

// @Bind ^mainMenuBlock.onBlockClick
!function(self, arg) {
	menuControl(self, arg,false);
};

//@Bind ^mainMenuBlock.onBlockDoubleClick
!function(self, arg) {
	menuControl(self, arg,true);
};

//@Bind ^mainMenuBtn.onClick
!function(self, arg) {
	var list = view.get("^mainMenuBtn");
	list.each(function(b){
		b.set("toggled",false);		
	});
	self.set("toggled",true);
	var index = self.get("userData");
	if(!index) index =0;
	view.get("#cardBookNav").set("currentIndex",index);
};


//@Bind ^mainMenuItem.onClick
!function(self,arg,btnChanel) {
    var index = self.get("userData");
	if(!index) index =0;
	btnChanel.set("caption",self.get("caption"));
	view.get("#cardBookNav").set("currentIndex",index);
};

window.menuControl = function(self, arg,flushTag){
	var data = arg.data;
	if(data.url && data.url != "#"){
		if(data.name == "首页"){
			view.get("#tabControlWorkarea").set("currentIndex",0);
		}else{
			window.openUrlInFrameTab2(data.url,data.name,data.icon,flushTag);
		}
	}
}
 